<template>
    <div class="page-container-inner flex-auto">
        <div class="py-12">
            <div v-if="['loading', 'error'].indexOf(dataStatus) >= 0" class="text-center">
                <component-page-loading :status="dataStatus" @reload="getData"></component-page-loading>
            </div>
            <div v-else>
                <!--显示-->
                <div v-if="!dataEditStatus">
                    <el-form label-width="180px" class="detail">
                        <!--全局修正-->
                        <el-form-item :label="$t('game.setting.config.fishing.globals.global_revise')">
                            {{ data.globals.global_revise }}
                        </el-form-item>
                        <el-row>
                            <!--房间鱼上限-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.room_fish_max')">
                                    {{ data.globals.room_fish_max }}
                                </el-form-item>
                            </el-col>
                            <!--房间子弹上限-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.room_bullet_max')">
                                    {{ data.globals.room_bullet_max }}
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <!--心跳配置-->
                        <el-divider>{{ $t('game.setting.config.fishing.globals.heartbeat.title') }}</el-divider>
                        <el-row>
                            <!--心跳修正系数-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.heartbeat.revise_ratio')">
                                    {{ data.globals.heartbeat.revise_ratio }}
                                </el-form-item>
                            </el-col>
                            <!--心跳值累计系数-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.heartbeat.value_add_ratio')">
                                    {{ data.globals.heartbeat.value_add_ratio }}
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <!--rtp周期控制-->
                        <el-divider>{{ $t('game.setting.config.fishing.globals.rtp_period.title') }}</el-divider>
                        <el-row>
                            <!--(初始值) 玩家消耗-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.init.cost')">
                                    {{ data.globals.rtp_period.init.cost }}
                                </el-form-item>
                            </el-col>
                            <!--(初始值) 玩家获得-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.init.gain')">
                                    {{ data.globals.rtp_period.init.gain }}
                                </el-form-item>
                            </el-col>
                            <!--出分加成-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.add_rate')">
                                    {{ data.globals.rtp_period.add_rate }}
                                </el-form-item>
                            </el-col>
                            <!--出分时长-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.add_time')">
                                    {{ data.globals.rtp_period.add_time }}s
                                </el-form-item>
                            </el-col>
                            <!--吃分加成-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.sub_rate')">
                                    {{ data.globals.rtp_period.sub_rate }}
                                </el-form-item>
                            </el-col>
                            <!--吃分时长-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.sub_time')">
                                    {{ data.globals.rtp_period.sub_time }}s
                                </el-form-item>
                            </el-col>
                            <!--RTP期望值-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.rtp_expect')">
                                    {{ data.globals.rtp_period.rtp_expect }}
                                </el-form-item>
                            </el-col>
                            <!--周期重置间隔-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.reset_time')">
                                    {{ data.globals.rtp_period.reset_time }}s
                                </el-form-item>
                            </el-col>
                            <!--最近收益时长-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.last_duration')">
                                    {{ data.globals.rtp_period.last_duration }}h
                                </el-form-item>
                            </el-col>
                            <!--随机倍数范围-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.period_time')">
                                    {{ data.globals.rtp_period.period_time }}
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <!--个人保底修正-->
                        <el-divider>{{ $t('game.setting.config.fishing.globals.person_revise.title') }}</el-divider>
                        <el-row>
                            <!--(初始值) 玩家消耗-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.person_revise.init.cost')">
                                    {{ data.globals.person_revise.init.cost }}
                                </el-form-item>
                            </el-col>
                            <!--(初始值) 玩家获得-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.person_revise.init.gain')">
                                    {{ data.globals.person_revise.init.gain }}
                                </el-form-item>
                            </el-col>
                            <!--最近收益条数-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.person_revise.last_count')">
                                    {{ data.globals.person_revise.last_count }}
                                </el-form-item>
                            </el-col>
                            <!--个控保底设置-->
                            <el-col :md="24">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.person_revise.revise.title')">
                                    <el-table :data="data.globals.person_revise.revise" border size="small" class="leading-normal" style="max-width:450px">
                                        <el-table-column :label="$t('game.setting.config.fishing.globals.person_revise.revise.range')" prop="range" min-width="140">
                                            <template slot-scope="scope">{{ scope.row.range }}</template>
                                        </el-table-column>
                                        <el-table-column :label="$t('game.setting.config.fishing.globals.person_revise.revise.value')" prop="value" min-width="100"></el-table-column>
                                    </el-table>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <!--鱼种修正-->
                        <el-divider>{{ $t('game.setting.config.fishing.globals.fish_revise.title') }}</el-divider>
                        <el-form-item :label="$t('game.setting.config.fishing.globals.fish_revise.title')">
                            <el-table :data="data.globals.fish_revise" border size="small" class="leading-normal" style="max-width:670px">
                                <el-table-column :label="$t('game.setting.config.fishing.globals.fish_revise.id')" prop="id" min-width="100"></el-table-column>
                                <el-table-column :label="$t('game.setting.config.fishing.globals.fish_revise.name')" prop="name" min-width="100"></el-table-column>
                                <el-table-column :label="$t('game.setting.config.fishing.globals.fish_revise.mapct')" prop="mapct" min-width="100"></el-table-column>
                                <el-table-column :label="$t('game.setting.config.fishing.globals.fish_revise.add_mapct')" prop="add_mapct" min-width="100"></el-table-column>
                                <el-table-column :label="$t('game.setting.config.fishing.globals.fish_revise.sub_mapct')" prop="sub_mapct" min-width="100"></el-table-column>
                            </el-table>
                        </el-form-item>
                        <!--操作-->
                        <el-form-item>
                            <el-button @click="editData">{{ $t('action.edit') }}</el-button>
                        </el-form-item>
                    </el-form>
                </div>
                <!--编辑-->
                <div v-if="dataEditStatus">
                    <el-form label-width="180px" :model="dataCache">
                        <!--全局修正-->
                        <el-form-item :label="$t('game.setting.config.fishing.globals.global_revise')"
                                      :error="Boolean(msg.errors[`globals.global_revise`]) ? msg.errors[`globals.global_revise`][0] : ''">
                            <el-input class="small" v-model.number="dataCache.globals.global_revise" type="number"></el-input>
                        </el-form-item>
                        <el-row>
                            <!--房间鱼上限-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.room_fish_max')"
                                              :error="Boolean(msg.errors['globals.room_fish_max']) ? msg.errors['globals.room_fish_max'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.room_fish_max" type="number"></el-input>
                                </el-form-item>
                            </el-col>
                            <!--房间子弹上限-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.room_bullet_max')"
                                              :error="Boolean(msg.errors['globals.room_bullet_max']) ? msg.errors['globals.room_bullet_max'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.room_bullet_max" type="number"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <!--心跳配置-->
                        <el-divider>{{ $t('game.setting.config.fishing.globals.heartbeat.title') }}</el-divider>
                        <el-row>
                            <!--心跳修正系数-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.heartbeat.revise_ratio')"
                                              :error="Boolean(msg.errors['globals.heartbeat.revise_ratio']) ? msg.errors['globals.heartbeat.revise_ratio'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.heartbeat.revise_ratio" type="number"></el-input>
                                    <div class="text-gray-400">{{ $t('game.setting.config.fishing.globals.heartbeat.revise_ratio_desc') }}</div>
                                </el-form-item>
                            </el-col>
                            <!--心跳值累计系数-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.heartbeat.value_add_ratio')"
                                              :error="Boolean(msg.errors['globals.heartbeat.value_add_ratio']) ? msg.errors['globals.heartbeat.value_add_ratio'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.heartbeat.value_add_ratio" type="number"></el-input>
                                    <div class="text-gray-400">{{ $t('game.setting.config.fishing.globals.heartbeat.value_add_ratio_desc') }}</div>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <!--rtp周期控制-->
                        <el-divider>{{ $t('game.setting.config.fishing.globals.rtp_period.title') }}</el-divider>
                        <el-row>
                            <!--(初始值) 玩家消耗-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.init.cost')"
                                              :error="Boolean(msg.errors['globals.rtp_period.init.cost']) ? msg.errors['globals.rtp_period.init.cost'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.rtp_period.init.cost" type="number"></el-input>
                                </el-form-item>
                            </el-col>
                            <!--(初始值) 玩家获得-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.init.gain')"
                                              :error="Boolean(msg.errors['globals.rtp_period.init.gain']) ? msg.errors['globals.rtp_period.init.gain'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.rtp_period.init.gain" type="number"></el-input>
                                </el-form-item>
                            </el-col>
                            <!--出分加成-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.add_rate')"
                                              :error="Boolean(msg.errors['globals.rtp_period.add_rate']) ? msg.errors['globals.rtp_period.add_rate'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.rtp_period.add_rate" type="number"></el-input>
                                </el-form-item>
                            </el-col>
                            <!--出分时长-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.add_time')"
                                              :error="Boolean(msg.errors['globals.rtp_period.add_time']) ? msg.errors['globals.rtp_period.add_time'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.rtp_period.add_time" type="number">
                                        <span slot="suffix">s</span>
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <!--吃分加成-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.sub_rate')"
                                              :error="Boolean(msg.errors['globals.rtp_period.sub_rate']) ? msg.errors['globals.rtp_period.sub_rate'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.rtp_period.sub_rate" type="number"></el-input>
                                </el-form-item>
                            </el-col>
                            <!--吃分时长-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.sub_time')"
                                              :error="Boolean(msg.errors['globals.rtp_period.sub_time']) ? msg.errors['globals.rtp_period.sub_time'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.rtp_period.sub_time" type="number">
                                        <span slot="suffix">s</span>
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <!--RTP期望值-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.rtp_expect')"
                                              :error="Boolean(msg.errors['globals.rtp_period.rtp_expect']) ? msg.errors['globals.rtp_period.rtp_expect'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.rtp_period.rtp_expect" type="number"></el-input>
                                </el-form-item>
                            </el-col>
                            <!--周期重置间隔-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.reset_time')"
                                              :error="Boolean(msg.errors['globals.rtp_period.reset_time']) ? msg.errors['globals.rtp_period.reset_time'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.rtp_period.reset_time" type="number">
                                        <span slot="suffix">s</span>
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <!--最近收益时长-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.last_duration')"
                                              :error="Boolean(msg.errors['globals.rtp_period.last_duration']) ? msg.errors['globals.rtp_period.last_duration'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.rtp_period.last_duration" type="number">
                                        <span slot="suffix">h</span>
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <!--随机倍数范围-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.rtp_period.period_time')"
                                              :error="Boolean(msg.errors['globals.rtp_period.period_time.0']) ? msg.errors['globals.rtp_period.period_time.0'][0] : ''
                                                   || Boolean(msg.errors['globals.rtp_period.period_time.1']) ? msg.errors['globals.rtp_period.period_time.1'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.rtp_period.period_time[0]" type="number"></el-input>
                                    <el-input class="small" v-model.number="dataCache.globals.rtp_period.period_time[1]" type="number"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <!--个人保底修正-->
                        <el-divider>{{ $t('game.setting.config.fishing.globals.person_revise.title') }}</el-divider>
                        <el-row>
                            <!--(初始值) 玩家消耗-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.person_revise.init.cost')"
                                              :error="Boolean(msg.errors['globals.person_revise.init.cost']) ? msg.errors['globals.person_revise.init.cost'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.person_revise.init.cost" type="number"></el-input>
                                </el-form-item>
                            </el-col>
                            <!--(初始值) 玩家获得-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.person_revise.init.gain')"
                                              :error="Boolean(msg.errors['globals.person_revise.init.gain']) ? msg.errors['globals.person_revise.init.gain'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.person_revise.init.gain" type="number"></el-input>
                                </el-form-item>
                            </el-col>
                            <!--最近收益条数-->
                            <el-col :md="12">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.person_revise.last_count')"
                                              :error="Boolean(msg.errors['globals.person_revise.last_count']) ? msg.errors['globals.person_revise.last_count'][0] : ''">
                                    <el-input class="small" v-model.number="dataCache.globals.person_revise.last_count" type="number"></el-input>
                                </el-form-item>
                            </el-col>
                            <!--个控保底设置-->
                            <el-col :md="24">
                                <el-form-item :label="$t('game.setting.config.fishing.globals.person_revise.revise.title')" :error="error_globals_person_revise">
                                    <div class="flex flex-nowrap">
                                        <div>
                                            <div class="text-aux">{{ $t('game.setting.config.fishing.globals.person_revise.revise.range') }}</div>
                                            <div class="mb-2 flex flex-nowrap" v-for="(item,index) in dataCache.globals.person_revise.revise">
                                                <el-input class="small" v-model.number="dataCache.globals.person_revise.revise[index].range[0]" type="number"></el-input>
                                                <el-input class="small" v-model.number="dataCache.globals.person_revise.revise[index].range[1]" type="number"></el-input>
                                            </div>
                                        </div>
                                        <div class="ml-2">
                                            <div class="text-aux">{{ $t('game.setting.config.fishing.globals.person_revise.revise.value') }}</div>
                                            <div class="mb-2 flex flex-nowrap" v-for="(item,index) in dataCache.globals.person_revise.revise">
                                                <el-input class="small" v-model.number="dataCache.globals.person_revise.revise[index].value" type="number"></el-input>
                                                <div class="ml-1">
                                                    <el-button size="small" icon="el-icon-close" circle @click="removeItemOrAdd(dataCache.globals.person_revise.revise, index, reviseItem)"></el-button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <el-button size="small" @click="addItem(dataCache.globals.person_revise.revise,reviseItem)">{{ $t('action.add') }}</el-button>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <!--鱼种修正-->
                        <el-divider>{{ $t('game.setting.config.fishing.globals.fish_revise.title') }}</el-divider>
                        <el-form-item :label="$t('game.setting.config.fishing.globals.fish_revise.title')" :error="error_globals_fish_revise">
                            <div class="flex flex-nowrap">
                                <div>
                                    <div class="text-aux">{{ $t('game.setting.config.fishing.globals.fish_revise.id') }}</div>
                                    <div class="mb-2 flex flex-nowrap" v-for="(item,index) in dataCache.globals.fish_revise">
                                        <el-input class="small" v-model.number="dataCache.globals.fish_revise[index].id" type="number"></el-input>
                                    </div>
                                </div>
                                <div>
                                    <div class="text-aux">{{ $t('game.setting.config.fishing.globals.fish_revise.name') }}</div>
                                    <div class="mb-2 flex flex-nowrap" v-for="(item,index) in dataCache.globals.fish_revise">
                                        <el-input class="small" v-model="dataCache.globals.fish_revise[index].name"></el-input>
                                    </div>
                                </div>
                                <div class="ml-2">
                                    <div class="text-aux">{{ $t('game.setting.config.fishing.globals.fish_revise.mapct') }}</div>
                                    <div class="mb-2 flex flex-nowrap" v-for="(item,index) in dataCache.globals.fish_revise">
                                        <el-input class="small" v-model.number="dataCache.globals.fish_revise[index].mapct" type="number"></el-input>
                                    </div>
                                </div>
                                <div class="ml-2">
                                    <div class="text-aux">{{ $t('game.setting.config.fishing.globals.fish_revise.add_mapct') }}</div>
                                    <div class="mb-2 flex flex-nowrap" v-for="(item,index) in dataCache.globals.fish_revise">
                                        <el-input class="small" v-model.number="dataCache.globals.fish_revise[index].add_mapct" type="number"></el-input>
                                    </div>
                                </div>
                                <div class="ml-2">
                                    <div class="text-aux">{{ $t('game.setting.config.fishing.globals.fish_revise.sub_mapct') }}</div>
                                    <div class="mb-2 flex flex-nowrap" v-for="(item,index) in dataCache.globals.fish_revise">
                                        <el-input class="small" v-model.number="dataCache.globals.fish_revise[index].sub_mapct" type="number"></el-input>
                                        <div class="ml-1">
                                            <el-button size="small" icon="el-icon-close" circle @click="removeItemOrAdd(dataCache.globals.fish_revise, index, fishReviseItem)"></el-button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <el-button size="small" @click="addItem(dataCache.globals.fish_revise,fishReviseItem)">{{ $t('action.add') }}</el-button>
                        </el-form-item>
                        <!--操作-->
                        <el-form-item>
                            <el-button type="primary" @click="onSubmit">{{ $t('action.save') }}</el-button>
                            <el-button @click="dataEditStatus = false">{{ $t('action.cancel') }}</el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </div>
        </div>
    </div>
</template>

<script>

export default {
    props: ['activeName'],
    data() {
        return {
            initStatus: false,
            dataStatus: 'dle',
            data: {
                globals: {
                    global_revise: null, //全局修正
                    room_fish_max: null, //房间鱼上限
                    room_bullet_max: null, //房间子弹上限
                    heartbeat: { //心跳配置
                        revise_ratio: null, //心跳修正系数
                        value_add_ratio: null, //心跳值累计系数
                    },
                    rtp_period: { //rtp周期控制
                        init: { //初始值
                            cost: null, //玩家消耗
                            gain: null, //玩家获得
                        },
                        add_rate: null, //出分加成
                        add_time: null, //出分时长（秒）
                        sub_rate: null, //吃分加成
                        sub_time: null, //吃分时长（秒）
                        rtp_expect: null, //rtp期望值
                        reset_time: null, //周期重置间隔（秒）
                        period_time: [null, null], //随机倍数范围
                        last_duration: null, //最近多长时间的收益【0则为所有记录】（小时）
                    },
                    person_revise: { //个控保底修正
                        init: { //初始值
                            cost: null, //玩家消耗
                            gain: null, //玩家获得
                        },
                        revise: [{ //个控保底设置
                            range: [null, null], //rtp值范围
                            value: null, //修正系数
                        }],
                        last_count: null, //最近多长条的收益【0则为所有记录】
                    },
                    fish_revise: [{ //鱼种修正
                        id: null, //鱼种ID
                        name: '', //鱼种名称
                        mapct: null, //修正系数
                        add_mapct: null, //修正系数【出】
                        sub_mapct: null, //修正系数【吃】
                    }],
                }
            },
            reviseItem: {
                range: [null, null], //rtp值范围
                value: null, //修正系数
            },
            fishReviseItem: {
                id: null, //鱼种ID
                name: '', //鱼种名称
                mapct: null, //修正系数
                add_mapct: null, //修正系数【出】
                sub_mapct: null, //修正系数【吃】
            },
            dataEditStatus: false,
            dataCache: {},
            msg: {
                code: 200,
                message: '',
                errors: {},
            },
        }
    },
    computed: {
        error_globals_person_revise: function () {
            for (let key in this.msg.errors) {
                if (_.startsWith(key, 'globals.person_revise.revise')) {
                    return this.msg.errors[key][0];
                }
            }
        },
        error_globals_fish_revise: function () {
            for (let key in this.msg.errors) {
                if (_.startsWith(key, 'globals.fish_revise')) {
                    return this.msg.errors[key][0];
                }
            }
        },
    },
    watch: {
        activeName: {
            immediate: true,
            handler(n, o) {
                if (n == 'system' && !this.initStatus) {
                    // 标记初始化
                    this.initStatus = true;
                    // 获取数据
                    this.getData();
                }
            }
        },
    },
    methods: {
        getData() {
            this.dataStatus = 'loading';
            // 获取数据
            axios.get(`/game/setting/config/fishing/${this.$route.params.game}/getConfig`).then((response) => {
                if (response.data.resp_msg.code == 200) {
                    if (response.data.resp_data.globals != null) {
                        this.data = response.data.resp_data;
                    }
                    if (this.data.globals.fish_revise == null) {
                        this.data.globals.fish_revise = [this.fishReviseItem];
                    }
                    this.dataStatus = 'dle';
                } else {
                    this.dataStatus = 'error';
                }
            })
        },
        initMsg() {
            this.msg.code = 200;
            this.msg.message = '';
            this.msg.errors = {};
        },
        editData() {
            // 重置验证
            this.initMsg();
            // 克隆数据
            this.dataCache = _.cloneDeep(this.data);
            // 编辑状态
            this.dataEditStatus = true;
        },
        addItem(configs, item) {
            configs.push(_.cloneDeep(item));
        },
        removeItem(configs, index) {
            configs.splice(index, 1);
        },
        removeItemOrAdd(configs, index, item) {
            this.removeItem(configs, index);
            if (!configs.length) {
                this.addItem(configs, item);
            }
        },
        onSubmit() {
            this.initMsg();
            // loading 状态 start
            let loading = this.$loading();
            // 保存数据
            axios.post(`/game/setting/config/fishing/${this.$route.params.game}/update`, this.dataCache).then((response) => {
                // loading 状态 close
                loading.close();
                // 逻辑处理
                if (response.data.resp_msg.code == 200) {
                    this.$message({
                        type: 'success',
                        message: this.$t('messages.succeeded', {status: this.$t('action.save')}),
                        showClose: true
                    });
                    this.dataEditStatus = false;
                    // 更新数据
                    this.data = response.data.resp_data;
                } else if (_.includes([42000], response.data.resp_msg.code)) {
                    this.$message({
                        type: 'error',
                        message: response.data.resp_msg.message,
                        showClose: true
                    });
                    this.msg = response.data.resp_msg;
                } else {
                    this.$message({
                        type: 'error',
                        dangerouslyUseHTMLString: true,
                        message: this.$t('messages.failed', {status: this.$t('action.save')}) + `<div class="mt-2">${response.data.resp_msg.message}</div>`,
                        showClose: true
                    });
                }
            })
        },
    }
}
</script>

<style lang="scss">

</style>
